package db

import (
	"center/db/models"
	"common/uuid"
	"context"
)

const DefaultBucketName = "default"

func (d *CenterDB) GetBucketByName(ctx context.Context, bucket string, ownerId uuid.UUID) (b *models.Bucket, err error) {
	err = d.db.WithContext(ctx).Where("bucket = ? and owner_id = ?", bucket, ownerId).Take(&b).Error
	return
}

func (d *CenterDB) AddBucket(ctx context.Context, bucket *models.Bucket) error {
	if bucket.ID.IsZero() {
		uid, err := uuid.New()
		if err != nil {
			return err
		}
		bucket.ID = uid
	}
	return d.db.WithContext(ctx).Create(&bucket).Error
}
